package com.corpgovernment.organization.service;

import com.corpgovernment.organization.entity.db.MbOrgEmployeeOpenCardRecord;
import com.corpgovernment.organization.mapper.MbOrgEmployeeOpenCardRecordMapper;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Service
public class MbOrgEmployeeOpenCardRecordService {

    @Autowired
    private MbOrgEmployeeOpenCardRecordMapper mbOrgEmployeeOpenCardRecordMapper;

    public MbOrgEmployeeOpenCardRecord selectByUid(String uid){
        Example example = new Example(MbOrgEmployeeOpenCardRecord.class);
        example.createCriteria().andEqualTo("platUid", uid);
        List<MbOrgEmployeeOpenCardRecord> mbOrgEmployeeOpenCardRecords = mbOrgEmployeeOpenCardRecordMapper.selectByExample(example);
        if (CollectionUtils.isNotEmpty(mbOrgEmployeeOpenCardRecords)){
            return mbOrgEmployeeOpenCardRecords.get(0);
        }
        return null;
    }

    public boolean insert(MbOrgEmployeeOpenCardRecord record){
        if (Objects.isNull(record)){
            return false;
        }
        return mbOrgEmployeeOpenCardRecordMapper.insertSelective(record) > 0;
    }
    public boolean update(MbOrgEmployeeOpenCardRecord record){
        if (Objects.isNull(record)){
            return false;
        }
        return mbOrgEmployeeOpenCardRecordMapper.updateByPrimaryKeySelective(record) > 0;
    }

    public List<MbOrgEmployeeOpenCardRecord> selectALL(){
        List<MbOrgEmployeeOpenCardRecord> mbOrgEmployeeOpenCardRecords = mbOrgEmployeeOpenCardRecordMapper.selectAll();
        if (CollectionUtils.isEmpty(mbOrgEmployeeOpenCardRecords)){
            return Collections.emptyList();
        }
        return mbOrgEmployeeOpenCardRecords;
    }

}
